/*
 * @Author: xiaosihan
 * @Date: 2024-10-16 20:49:30
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2024-10-16 21:05:18
 */

import { Object3D } from "three";
import MeshBase from "three-base/MeshBase";
import SpriteText from "three-base/SpriteText";
import Point1GLB from "./point1.glb?url";

// 点位文字
export default class PointText extends Object3D {
    constructor(text = "PointText") {
        super();
        this.setText(text);
    }

    //点位模型
    pointMesh = (() => {
        const pointMesh = new MeshBase(Point1GLB);
        pointMesh.addEventListener("loaded", () => {
            const anima = pointMesh.getAnimas();
            pointMesh.setAnimas(anima[0]);
        });
        this.add(pointMesh);
        return pointMesh;
    })();

    //文字模型
    textMesh = (() => {
        const textMesh = new SpriteText("PointText");
        textMesh.padding = 2;
        textMesh.strokeColor = "#111";
        textMesh.strokeWidth = 2;
        textMesh.scale.multiplyScalar(0.15);
        textMesh.position.set(0, 6, 0);
        this.add(textMesh);
        return textMesh;
    })();

    setText(text: string) {
        this.textMesh.text = text;
        this.textMesh.scale.multiplyScalar(0.2);
    }
}
